package com.example.matchingengine.config;

import org.springframework.stereotype.Component;

/**
 * Topic配置类
 * 负责管理每个币对对应的MQ Topic名称
 */
@Component
public class TopicConfig {
    
    // Topic前缀
    private static final String ORDER_TOPIC_PREFIX = "matching-engine-order-";
    private static final String ORDER_STATUS_TOPIC_PREFIX = "matching-engine-order-status-";
    private static final String TRADE_TOPIC_PREFIX = "matching-engine-trade-";
    private static final String CANCEL_ORDER_TOPIC_PREFIX = "matching-engine-cancel-order-";
    
    /**
     * 获取订单Topic名称
     * @param symbol 币对符号，如 BTCUSDT
     * @return Topic名称，如 matching-engine-order-BTCUSDT
     */
    public String getOrderTopic(String symbol) {
        return ORDER_TOPIC_PREFIX + symbol.toUpperCase();
    }
    
    /**
     * 获取订单状态Topic名称
     * @param symbol 币对符号，如 BTCUSDT
     * @return Topic名称，如 matching-engine-order-status-BTCUSDT
     */
    public String getOrderStatusTopic(String symbol) {
        return ORDER_STATUS_TOPIC_PREFIX + symbol.toUpperCase();
    }
    
    /**
     * 获取成交事件Topic名称
     * @param symbol 币对符号，如 BTCUSDT
     * @return Topic名称，如 matching-engine-trade-BTCUSDT
     */
    public String getTradeTopic(String symbol) {
        return TRADE_TOPIC_PREFIX + symbol.toUpperCase();
    }
    
    /**
     * 获取取消订单Topic名称
     * @param symbol 币对符号，如 BTCUSDT
     * @return Topic名称，如 matching-engine-cancel-order-BTCUSDT
     */
    public String getCancelOrderTopic(String symbol) {
        return CANCEL_ORDER_TOPIC_PREFIX + symbol.toUpperCase();
    }
    
    /**
     * 获取消费者组名称
     * @param symbol 币对符号
     * @param type 消费者类型：order, order-status, trade, cancel-order
     * @return 消费者组名称
     */
    public String getConsumerGroup(String symbol, String type) {
        return "matching-engine-" + type + "-consumer-" + symbol.toUpperCase();
    }
}